function getCookie(){
    // if(window.plus) {   //hbuilder的打包
    //     alert(plus.navigator.getCookie( "http://localhost:88" ))
    //     return plus.navigator.getCookie( "http://localhost:88" );
    // }
    var cookie = {};
    var all = document.cookie;
    if( all == "" ){
        return {};
    }
    var list = all.split(";");
    for( var i = 0; i < list.length; i++ ){
        var cok = list[i];
        var p = cok.indexOf("=");
        var name = cok.substring( 0,p ).trim();
        var value = cok.substring(p+1);
        value = decodeURIComponent( value );
        cookie[ name ] = value;
    }
    return cookie || {};
}
function setCookie(name,value,dayToLive){
    // if(window.plus && window.browser.isApp){
    //     plus.navigator.setCookie("http://localhost:88", name + '='+ value +'; expires=Friday,24-Jan-2015 16:24:36 GMT; path=/');
    //     return;
    // }
    var cookie = name + "=" + encodeURIComponent( value );
    if( typeof dayToLive === "number"){
        cookie += ";max-age=" + ( dayToLive * 60 * 60 * 24 );
    }
    cookie += ";path=/";
    document.cookie = cookie;
}
function deleteCookie( name ){
    // if(window.plus && window.browser.isApp){
    //     plus.navigator.setCookie("http://localhost:88", name + '=""; expires=Friday,24-Jan-2015 16:24:36 GMT; path=/');
    // }
    // var domain = location.host;
    var cookie = name + '=;max-age=0;path=/';
    document.cookie = cookie;
    // var cookie = name + "=" + ";max-age=0;path=/;domain=."+domain;  //去除qq登录后，token里的domain前的地址有一个点
    // document.cookie = cookie;
}

function clearAllCookie() {   //慎用。可能会删掉app种下的app信息。 可能用不到
    var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
    if(keys) {
        for(var i = keys.length; i--;)
            document.cookie = keys[i] + '=;max-age=0;path=/';
    }
}

export default {
    getCookie: getCookie,
    setCookie: setCookie,
    deleteCookie: deleteCookie,
    clearAllCookie: clearAllCookie
}